C Nested If Else Statement

Writing an if or else statement inside another if or else statement is called a Nested If Else Statement.

Syntax of Nested If Else Statement


if (condition1) {
    // Executes when condition1 is true
    if (condition2) {
        // Statement 1
    } else {
        // Statement 2
    }
} else {
    if (condition3) {
        // Statement 3
    } else {
        // Statement 4
    }
}

            

Flowchart of Nested If Else Statement

Example


#include < stdio.h>

void main() {
    int number = 15;
    if (number > 0) {
        if (number > 10) {
            printf("The number is greater than 10.\n");
        } else {
            printf("The number is positive but less than or equal to 10.\n");
        }
    } else {
        printf("The number is zero or negative.\n");
    }
}